﻿#ifndef SERIAL_FUNC_H
#define SERIAL_FUNC_H

#include <QThread>
#include <QtSerialPort/QSerialPort>
#include <QtSerialPort/QSerialPortInfo>
#include <QSettings>
#include <QTimer>
#include "global_define.h"

class serial_func : public QThread
{
    Q_OBJECT
public:
    explicit serial_func(QObject *parent = 0);
    int open();
    void close();
    void send(QByteArray buf);
    QByteArray uart_getString();
    static QStringList findAvailablePort();
private:
    QSerialPort *serial;
    int openFlag;//串口打开标志
    QSettings *setting_config;
    QTimer *timer;
    QByteArray getString;//串口接收信息
    QByteArray sendString;
    int resendNum;//重发计数
signals:
    void sig_readfinish(int );

protected:
    void run();

public slots:
    void timerOut_slot();
    void readfinish_slot(int);
};

#endif // SERIAL_FUNC_H
